#ifndef _NET__H___
#define _NET__H___
#include <SDL/SDL.h>
#include <SDL/SDL_net.h>

#include <vector>
#include <cstring>

#include "game.h"

class Server {
  public:
    bool _running;

    int _identifier;
    struct Client_data {
    	TCPsocket sock;
	    int id;
		Client_data() {};
		Client_data(const Client_data& d) {
			sock = d.sock;
			id = d.id;
		};
		~Client_data() {}
    };

    int _num_clients;

    int initserver(int);
    int main_server_thread();
    void freeserver();

	Server();
	~Server();

  private:

	Game *_game;

    int put(TCPsocket , const char *);
    int recv(TCPsocket , char *&);
    
    void do_command(char *, Client_data *);         

    TCPsocket _server_sock;    

    std::vector<Client_data> _clients;

    Client_data *add_client(TCPsocket, int);
    SDLNet_SocketSet create_sockset();
    
    void fix_string(char *);

 
};

#endif
